package com.pinyoumei.app.view.dialog;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Shader;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.pinyoumei.app.R;
import com.pinyoumei.app.adapter.ShopRulesAdapter;
import com.pinyoumei.app.bean.ToBaoBean;

import java.util.List;

/**
 * 温馨提示的Dialog
 */
public class ShopRulesDialog extends Dialog  {
    private Context context;
    private int layoutResID;      // 布局文件id


    private String title;
    private TextView tv_rules;
    private TextView tv_rules2;
    private List<ToBaoBean.ResultBean.RoleListBean> role_list;

    public ShopRulesDialog(Context context){
        super(context);
        this.context = context;
    }

    public ShopRulesDialog(Context context, boolean cancelable, OnCancelListener cancelListener){
        super(context,cancelable,cancelListener);
    }
    public ShopRulesDialog(Context context, int layoutResID, String title, List<ToBaoBean.ResultBean.RoleListBean> role_list){
        super(context, R.style.dialogStyle); //dialog的样式
        this.context = context;
        this.layoutResID = layoutResID;
        this.title = title;
        this.role_list = role_list;

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Window dialogWindow = getWindow();
        dialogWindow.setGravity(Gravity.CENTER);//内部区域显示在中间
        //dialogWindow.setWindowAnimations(R.style.bottom_menu_animation);
        WindowManager.LayoutParams  lp = dialogWindow.getAttributes();
        DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();//获取屏幕宽高
        lp.width = (int)(displayMetrics.widthPixels * 0.9);//宽度设置为屏幕宽度的80%
        dialogWindow.setAttributes(lp);
        setCanceledOnTouchOutside(true);//点击Dialog外部消失
        setContentView(layoutResID);

        tv_rules = findViewById(R.id.tv_rules);
        LinearGradient mLinearGradient =new LinearGradient(0, 0, 0, tv_rules.getPaint().getTextSize(), Color.parseColor("#FF2F8E"), Color.parseColor("#FF354D"), Shader.TileMode.CLAMP);

        tv_rules.getPaint().setShader(mLinearGradient);

        tv_rules.invalidate();


        tv_rules2 = findViewById(R.id.tv_rules2);
        tv_rules2.setText(title);

       RecyclerView rv_rule = findViewById(R.id.rv_rule);
       rv_rule.setLayoutManager(new LinearLayoutManager(context,LinearLayoutManager.VERTICAL,false));
        ShopRulesAdapter shopRulesAdapter = new ShopRulesAdapter(R.layout.item_shop_rules,role_list);
        rv_rule.setAdapter(shopRulesAdapter);


    }

}
